package com.tongji.admin.service
{
	import com.tongji.admin.event.BrandAdminEvent;
	import com.tongji.admin.event.CantavilAdminEvent;
	import com.tongji.admin.event.GoodsTypeAdminEvent;
	import com.tongji.admin.vo.Brand;
	import com.tongji.admin.vo.Cantavil;
	import com.tongji.admin.vo.Goods;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/7/
	 */ 
	public class HouseDiyService extends Actor
	{
		public var remoteObject:RemoteObject;
		
		public function HouseDiyService()
		{
			super();
			
			var amfChannel:Array = [new AMFChannel(null, "http://localhost:88/Gateway.aspx")];
			//var amfChannel:Array = [new AMFChannel(null, "http://ssegrc.gotoip55.com/Gateway.aspx")];
			var channelSet:ChannelSet = new ChannelSet();
			channelSet.channels = amfChannel;
			
			remoteObject = new RemoteObject("fluorine");
			remoteObject.source = "HouseDiyService.HouseDiyAction";
			remoteObject.showBusyCursor = true;
			remoteObject.channelSet = channelSet;
			
			remoteObject.getOperation("getAllBrands").addEventListener(ResultEvent.RESULT, getAllBrandsHandler);
			remoteObject.getOperation("getAllBrands").addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		
		public function getBrands():void
		{
			remoteObject.getAllBrands();
			
		}
		
		private function getAllBrandsHandler(event:ResultEvent):void
		{
			dispatch(new BrandAdminEvent(BrandAdminEvent.UPDATE_BRANDS, null, event.result as ArrayCollection));
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(" fault :" + event.toString());
		}
	}
}